package com.benz.order.util.multithread;

public class ThreadTaskSyn2 implements Runnable {
    private int tickets=10;
    private final Object lock = new Object();
    @Override
    public void run() {
        while (true) {
            synchronized (lock) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                if (tickets > 0) {
                    System.out.println(Thread.currentThread().getName() + "卖出的票：" + tickets--);
                } else {
                    break;
                }
            }
        }
    }
}
